package ee.ts022.tuum.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import ee.ts022.tuum.domain.CstAddress;

@Repository
public class CustomerAddressDaoImpl extends DomainDao implements CustomerAddressDao {

	public CustomerAddressDaoImpl() {
		super(CstAddress.class);
	}

	@Transactional
	@Override
	public List<CstAddress> getAll() {
		return super.getAllDomain();
	}

	@Transactional
	@Override
	public CstAddress get(int id) {
		return super.getDomain(id);
	}

	@Transactional
	@Override
	public boolean save(CstAddress domain) {
		return super.saveDomain(domain);
	}

	@Transactional
	@Override
	public boolean insert(CstAddress domain) {
		return super.insertDomain(domain);
	}

	@Transactional
	@Override
	public boolean delete(CstAddress domain) {
		return super.deleteDomain(domain);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	@Override
	public List<CstAddress> getCustomerAddresses(int customer) {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(CstAddress.class);
		criteria.createCriteria("customer").add(Restrictions.eq("customer", customer));
		return (List<CstAddress>) criteria.list();
	}

}
